﻿using DevExpress.XtraBars;
using System;

namespace Inaction.UI
{
    public partial class BarManager : DevExpress.XtraBars.BarManager
    {
        private void InitExtenders()
        {
            if (IsDesignMode || BtnAddNew == null) return;
            if (InitExtendAction != null)
            {
                InitExtendAction(this);
            }
            if (ShowContextMenuExtendAction != null)
            {
                ShowToolbarsContextMenu += BarManager_ShowToolbarsContextMenu;
            }
            if (extendBar!=null && extendBar.ItemLinks.Count > 0)
            {
                this.Bars.Add(extendBar);
            }
        }
        Bar extendBar = null;
        public Bar GetExtendBar()
        {
            if (extendBar != null) return extendBar;
            var bar = new Bar(this);
            bar.BarName = "extendBar";
            bar.BarAppearance.SetWordWrap(DevExpress.Utils.WordWrap.Wrap);
            bar.OptionsBar.AllowQuickCustomization = false;
            bar.OptionsBar.AllowCollapse = false;
            bar.OptionsBar.AllowDelete = false;
            bar.OptionsBar.AllowRename = false;
            bar.OptionsBar.DisableClose = true;
            bar.OptionsBar.DisableCustomization = true;
            bar.DockStyle = BarDockStyle.Top;

            return bar;
        }

        #region ToolbarsContextMenu扩展
        BarItemLinkCollection barMenuLinks = new BarItemLinkCollection();
        void BarManager_ShowToolbarsContextMenu(object sender, ShowToolbarsContextMenuEventArgs e)
        {
            if (barMenuLinks.Count == 0)
            {
                ShowContextMenuExtendAction(this, barMenuLinks);
            }
            foreach (BarItemLink link in barMenuLinks)
            {
                e.ItemLinks.Add(link.Item, link.BeginGroup);
            }
        }
        public static event Action<BarManager, BarItemLinkCollection> ShowContextMenuExtendAction;
        #endregion

        public static event Action<BarManager> InitExtendAction;

    }
}
